using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ShipUIDrager : MonoBehaviour
{
    public Image m_Preview;
    public ShipUI m_ShipUI;

    public static ShipUIDrager Create(ShipUI shipUI = null)
    {
        GameObject theNew = new GameObject();
        var canvas = Utils.GetCanvas();
        if(canvas)
        {
            theNew.transform.SetParent(canvas.transform);
            theNew.transform.SetSiblingIndex(canvas.transform.childCount);
        }
        var shipUIDrager = theNew.AddComponent<ShipUIDrager>();
        shipUIDrager.m_Preview= theNew.AddComponent<Image>();
        shipUIDrager.m_Preview.raycastTarget = false;
        if (shipUI)
            shipUIDrager.Init(shipUI);
        return shipUIDrager;
    }
    private void Awake()
    {
    }
    void Start()
    {
        
    }

    void Update()
    {
        
    }
    public void Init(ShipUI shipUI)
    {
        if(shipUI == null)
        {
            return;
        }
        m_ShipUI = shipUI;
        var sprite = shipUI.m_PreviewPrefab;
        if (m_Preview != null)
        {
            m_Preview.sprite = sprite;
            m_Preview.color = new Color(1, 1, 1, 0.5f) ;
        }
     }
}
